<template>
  <div id="dialogUpReadImg">
    <el-dialog
      class="about-set"
      title="添加图片"
      :visible.sync="dialogData.isShow"
      width="600px"
      :before-close="labelHandleClose"
    >
      <uploadImg
        :maxLength="9"
        accept=".jpg,.png,.gif"
        @setImgInfo="setImgInfo"
      ></uploadImg>
      <span slot="footer" class="dialog-footer">
        <el-button type="success" @click="saveImg">确定</el-button>
        <el-button type="success" plain @click="cancelLabel">取 消</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import uploadImg from '@common/uploadImg' // 上传图片公共组件
export default {
  name: 'dialogUploadImg',
  msg: '阅读管理-我的发布---编辑器上传图片',
  props: ['dialogData'],
  components: {
    uploadImg
  },
  data() {
    return {
      loading: false,
      imgAry: []
    }
  },
  mounted() {},
  methods: {
    /* 图片上传成功后，获取返回结果 */
    setImgInfo(str) {
      this.imgAry = [...str]
    },
    cancelLabel() {
      // 关闭前清空
      this.dialogData.isShow = false
    },
    labelHandleClose(done) {
      this.cancelLabel()
      done()
    },
    saveImg() {
      if (this.imgAry.length === 0) {
        this.$message.warning('没有上传成功的图片！')
        return
      }
      this.$emit('setImgInfo', this.imgAry)
      this.cancelLabel()
    }
  }
}
</script>

<style lang="less">
#dialogUpReadImg {
  .el-dialog__body {
    padding-bottom: 20px !important;
  }
  .el-upload-dragger {
    width: 100%;
    height: 100%;
    border: 0;
  }
  .img-box {
    position: relative;
    float: left;
    overflow: hidden;
    background-color: #fff;
    border: 1px solid #c0ccda;
    border-radius: 6px;
    -webkit-box-sizing: border-box;
    box-sizing: border-box;
    width: 148px;
    height: 148px;
    margin: 0 8px 8px 0;
  }
  .el-img-box,
  .el-image {
    width: 148px;
    height: 148px;
  }
  .upload_tip {
    clear: both;
    color: #f00;
    font-size: 12px;
    padding-bottom: 5px;
  }
  i.icon {
    position: absolute;
    right: 0;
    top: 0;
    width: 26px;
    height: 22px;
    background: rgba(29, 200, 164, 0.8);
    z-index: 1;
    color: #fff;
    text-align: center;
    line-height: 22px;
    &.del {
      top: auto;
      bottom: 0;
      background: rgba(0, 0, 0, 0.5);
      cursor: pointer;
    }
  }
}
</style>
